using System;
using Microsoft.Xna.Framework;

namespace SpriteAnimations.Graphics.Animations
{
    class BlinkAnimation : SpriteAnimation
    {
        //
        // Fields
        //
        private TimeSpan blinkLength;
        private TimeSpan timeLeft;
        private bool isVisible = true;

        //
        // Constructors
        //
        public BlinkAnimation(TimeSpan blinkLength)
        {
            this.blinkLength = blinkLength;
            this.timeLeft = blinkLength;
        }

        //
        // Virtual Methods
        //
        public override void Animate(TimeSpan gameTime, SpriteParameters animatedParameters)
        {
            timeLeft -= gameTime;
            if (timeLeft.TotalSeconds < 0)
            {
                // we have elapsed, so blink
                isVisible = !isVisible;
                timeLeft = blinkLength;
            }

            animatedParameters.IsVisible = isVisible;
        }
    }
}
